import { login } from 'api/login'
const user = {
  state: {
    token: '',
    roles: null,
    isMasterAccount: true,
    loginUser: null
  },

  mutations: {
    //   SET_TOKEN: (state, token) => {
    //     state.token ="Bearer " +token 
    //   },
    settoken(state, info) {
      state.loginUser = info.username
      localStorage.setItem('token', info.token)
      console.log(state.loginUser);
    }
  },
  actions: {
    // 登录
    Login({ commit }, userInfo) {
      return new Promise((resolve, reject) => {
        login(userInfo).then(response => {
          // console.log(userInfo, response)
          resolve(response)
          console.log(response, '-----3');
          let data = {
            username: userInfo.username,
            token: response.data.result.token
          }
          commit('settoken', data)
          console.log('okk')
          
        }).catch(error => {
          // console.log("登录失败")
          reject(error)
        })
      })
    },
  },
  getters: {

  }
}

export default user